package com.neulogistics.contrib.procuredcenter.domain.model.aggregate;

import com.neulogistics.contrib.procuredcenter.domain.model.enumeration.PurchaseType;
import com.neulogistics.contrib.procuredcenter.domain.model.valueobject.PurchaseItem;
import com.neulogistics.infrastructure.ddd.domain.seedwork.Entity;
import com.neulogistics.infrastructure.ddd.domain.seedwork.IAggregateRoot;
import lombok.Data;

import java.util.Date;

@Data
public class PurchaseOrder extends Entity<Long> implements IAggregateRoot {
    /**
     * 采购单id
     */
    private Long purchaseOrderId;

    /**
     * 采购单类型：0:进货；1:退货
     */
    private PurchaseType purchaseType;

    /**
     * 关联中心库房id
     */
    private Integer warehouseId;

    /**
     * 采购项，{商品id、数量、单价、计量单位、供应商}
     */
    private PurchaseItem purchaseItem;

    /**
     * 采购单总计
     */
    private Double purchaseTotal;

    /**
     * 生成时间
     */
    private Date createTime;

    /**
     * 是否删除
     */
    private Integer deleted;

    public PurchaseOrder() {
    }

    public PurchaseOrder(Long purchaseOrderId, PurchaseType purchaseType,
                         Integer warehouseId, PurchaseItem purchaseItem) {
        this.purchaseOrderId = purchaseOrderId;
        this.purchaseType = purchaseType;
        this.warehouseId = warehouseId;
        this.purchaseItem = purchaseItem;
        this.purchaseTotal = calculatePurchaseTotal();
    }

    public Double calculatePurchaseTotal(){
        return purchaseItem.getGoodsPrice() * purchaseItem.getCount();
    }
}
